#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int main(int argc, char const* argv[])
{
    int i, n;
    int fd[2];
    int val;

    if (pipe(fd) < 0)
    {
        perror("pipe error");
        exit(0);
    }

    if ((val = fcntl(fd[1], F_GETFL, 0)) < 0) 
    {
        perror("fcntl error");
        exit(0);
    }

    val |= O_NONBLOCK;
    
    if (fcntl(fd[1], F_SETFL, val) < 0)
    {
        perror("fcntl error");
        exit(0);
    }

    for (n = 0; ; n++) {
        if ((i = write(fd[1], "a", 1)) != 1) {
            printf("write ret %d, ", i);
            break;
        }
    }

    printf("pipe capacity = %d\n", n);
    printf("_PC_PIPE_BUF = %ld\n", fpathconf(fd[1], _PC_PIPE_BUF));

    return 0;
}
